﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Reflection;

namespace XWeb.Code.Page
{
    public class UIBasePage : System.Web.UI.Page
    {
        private string _version = "";
        private string _phonekey = "";

        public string Version
        {
            get { return _version; }
        }

        public string PhoneKey
        {
            get { return _phonekey; }
        }

        protected override void OnInit(EventArgs e)
        {
            _version = GetValue(XConst.S_KEY_VERSION);
            _phonekey = GetValue(XConst.S_KEY_PHONEKEY);
            //XCommon.utils.LogUtil.Write(_phonekey);

            MethodInfo operateMethod = GetOperateMethodName();
            if (operateMethod != null)
            {
                try
                {
                    operateMethod.Invoke(this, null);
                }
                catch
                {
                }
            }
            base.OnInit(e);
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
        }

        public void WriteOut(string strText, string datatype)
        {
            Response.ContentType = datatype;
            Response.Write(strText);
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }

        public MethodInfo GetOperateMethodName()
        {
            string methodName = GetValue(XConst.S_KEY_GETMETHODKEY);
            if (string.IsNullOrEmpty(methodName))
            {
                return null;
            }
            return this.GetType().GetMethod(methodName);
        }

        public string GetValue(string key)
        {
            return Request.QueryString[key] ?? Request.Form[key] ?? "";
        }
    }
}